<template>
	<el-dialog title="导出内联配置" :visible.sync="visible" width="800px" :center="false" >
		 <div slot="title" class="dialog-header-title">
			<i class="el-icon-upload2" style="color: #FFF"></i>&nbsp;
			<span style="color: #FFF">导出内联配置</span>
		</div> 

		 <div  >
			 <el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">
			 		<el-row>
			 		<el-col :span="12">
						
						<el-form-item label="开发地址:" :label-col="{ span: 24 }"
													:wrapper-col="{ span: 16  }"  prop="esbSource">
													<el-select  v-model="form.esbSource" style="width: 100%"
														placeholder="开发地址"  >
														<el-option v-for="item in esbEnvironmentList" :key="item.ip" :label="item.ip"
															:value="item.ip">
														</el-option>
													</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
					<el-form-item label="文件清单:" :label-col="{ span: 24 }"
												:wrapper-col="{ span: 16  }" prop="esbFile">
					
					<!-- <el-upload  file-list="fileList" accept=".txt" :limit="1" multiple :auto-upload="false" action="#" :on-change="changeFile" style="text-align: left;">
						<el-button size="mini" type="success" style="width: 200px;"><i class="el-icon-upload"/>点击上传</el-button>
						<div slot="tip" class="el-upload__tip">*只能上传txt文件</div>
					</el-upload> -->
					<el-input type="textarea"
					:rows="10"
					v-model="form.esbFile"
					placeholder="eg:AHRCUApp/BusinessService/CBS/HTTPSRV_CBS_WLBZ_JSON_BusinessService" 
					
					>
						
					</el-input>
						</el-form-item>
						</el-col>
					</el-row>
					</el-form> 
			 
			 
		<!-- 	<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">
				<el-row>
					<el-col :span="24">
						<el-col :span="24">
							<el-form-item label="文件清单:" prop="id" > -->
								
						<!-- 	</el-form-item> 
						</el-col>
					</el-col>
				</el-row>
			</el-form> -->
		 </div> 
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false" size="mini">取 消</el-button>
			<el-button type="primary" @click="submit" size="mini" plain>确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
	"use strict";
		import { initFile, initOESBFile } from '@/api/release.js';
		import { getEsbEnvironmentByEsbFlg } from '@/api/environment.js';
		import { esbfileDown } from '@/api/requirementBatch.js';
	export default {
		data() {
			return {
			visible:false,
			/* fileList:[], */
			form:{
				qmsNo:'',
				batchNum:'',
				esbSource:'',
				esbFile:'',
				oesbSource: '',
				oesbFile: ""
			},
			esbEnvironmentList:[],
			rules: {
				esbSource: [{
					required: true,
					message: '请选择开发环境',
					trigger: ['blur', 'change']
				}],
			/* 	file: [{
					required: true,
					message: '请输入文件清单',
					trigger: ['blur', 'change']
				}], */
			}
			}
			
		},
		
		created() {
			this.getEsbEnvironmentList();
		},
		
		methods: {
			getEsbEnvironmentList(){
				getEsbEnvironmentByEsbFlg({"esbFlg":"01"}).then(response=>{
					this.esbEnvironmentList = response.data.extend; 
				})
			},
			ShowDialog(row){
				this.visible = true;
				//this.reset();
				Object.assign(this.form,row);
				this.getList();
				// this.from.esbSource ='';
				// this.from.esbFile ='';
				/* this.fileList =[] */
				
			},
			/* cancel(){
				this.visible = false;
			}, */
			/* changeFile(file,fileList){
				this.fileList = fileList;
			}, */
			
			getList() {
				esbfileDown({
						qmsNo:this.form.qmsNo,
						batchNum:this.form.batchNum
					}).then(response => {
						let obj = response.data.extend;
						this.form.esbFile=obj[0];
						this.form.oesbFile=obj[1];
					}).catch(error => {
					console.info("失败");
					console.info(error.message);
					});
			},
			
			
			submit(){
				this.$refs["form"].validate((valid)=>{
					if(valid){
					
						/* if(this.fileList.length==1){
							this.query.file = this.fileList[0].raw;
							
							 */
							/* let data = new FormData();
							data.append("file",this.query.file);
							data.append("qmsNo",this.query.qmsNo);
							data.append("batchNum",this.query.batchNum);
							data.append("esbSource",this.query.esbSource); */
							
						
							
							initFile(this.form).then(res => {
									
									let name = this.form.qmsNo+"_"+this.form.batchNum+"_ESB.zip";
									const blob = new Blob([res.data],{type:"application/zip"});
									const blobURL = window.URL.createObjectURL(blob);
									const aLink = document.createElement('a');
									aLink.href = blobURL;
									aLink.setAttribute('download',name);
									
									if(typeof aLink.download==='undefined'){
										aLink.setAttribute('target','_blank');
									}
									aLink.style.display = 'none';
									document.body.appendChild(aLink);
									aLink.click();
									document.body.removeChild(aLink);
									window.URL.revokeObjectURL(blob);
									this.$message({
										duration:5000,
										type: 'success',
										message: '生成文件成功'
									});	
									this.visible = false;
								}).catch(error => {
									this.$message({
										duration:5000,										
										type: 'error',
										message: error
									});
								});
								
						/* }else{
							ththis.$message({
						duration:5000,							type: 'error',
								message: '请上传文件'
							});	
						} */
						
						
						
						
					}
					});
			}
			
		}
	};
</script>
